/*
 *  Copyright 2017 Google Inc. All Rights Reserved.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.google.blockly.ohos.ui;

import com.google.blockly.ohos.control.BlocklyController;
import com.google.blockly.utils.LangUtils;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.dialog.IDialog;
import ohos.app.Context;

/**
 * Default dialog window shown when deleting a variable in the workspace.
 */
public class DeleteVariableDialog extends CommonDialog {
    private String mVariable;
    private int mCount;
    private BlocklyController mController;

    public DeleteVariableDialog(Context context) {
        super(context);
        CommonDialog commonDialog = new CommonDialog(context);
        commonDialog.setTitleText(LangUtils.interpolate("%{BKY_DELETE_VARIABLE}")
                .replace("%1", mVariable));
        commonDialog.setContentText(LangUtils.interpolate("%{BKY_DELETE_VARIABLE_CONFIRMATION}")
                .replace("%1", String.valueOf(mCount)).replace("%2", mVariable));
        commonDialog.setButton(1, LangUtils.interpolate("%{BKY_IOS_VARIABLES_DELETE_BUTTON}"), new ClickedListener() {
            @Override
            public void onClick(IDialog iDialog, int i) {
                mController.deleteVariable(mVariable);
            }
        });
    }


    public void setController(BlocklyController controller) {
        mController = controller;
    }

    public void setVariable(String variable, int count) {
        mVariable = variable;
        mCount = count;
    }
}
